/**
 * 
 */
package com.test002;

import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import chrriis.common.UIUtils;
import chrriis.dj.nativeswing.swtimpl.NativeInterface;
import chrriis.dj.nativeswing.swtimpl.components.JWebBrowser;

/**
 * @Title: WebPanel
 * @Description:
 * @author zhoumingyan
 * @date 2020年3月6日 下午3:41:32
 */
public class WebPanel extends JPanel {

	private JPanel webBrowserPanel;
	 
    private JWebBrowser webBrowser;
    
    public WebPanel(String url) {
    	//super(new BorderLayout());
    	UIUtils.setPreferredLookAndFeel();
        NativeInterface.open();
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
            	
                 webBrowserPanel = new JPanel(new BorderLayout());
                 webBrowser = new JWebBrowser();
                 webBrowser.navigate(url);
                 webBrowser.setButtonBarVisible(false);
                 webBrowser.setMenuBarVisible(false);
                 webBrowser.setBarsVisible(false);
                 webBrowser.setStatusBarVisible(false);
                 webBrowserPanel.add(webBrowser, BorderLayout.CENTER);
                 add(webBrowserPanel, BorderLayout.CENTER);
                 //执行Js代码
                 webBrowser.executeJavascript("alert('hello swing')");
            }
        });
        NativeInterface.runEventPump();
       
    }
    
    /**
     * 在swing里内嵌浏览器
     * @param url  要访问的url
     * @param title    窗体的标题
     */
    public  static void  openForm(String url,String title){
        UIUtils.setPreferredLookAndFeel();
        NativeInterface.open();
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
               
            }
        });
        NativeInterface.runEventPump();
    }

    
    public static void main(String[] args) {
        openForm("http://www.baidu.com","hello swing");
    }


}
